home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
linux-bo
/
dless-li
/
root.no
/
etc
/
rc.d
/
rc.bootp
< prev
next >
Wrap
Text File
|
1995-04-28
|
6KB
|
226 lines
####!/bin/sh
# Written to simply set the IP stuff up from the
# bootpc data.
# Last updated : Thu Aug 18 17:52:14 1994
# Jon Peatfield
#
# with modifications as suggested by Austin Donnelly, Chris Hall and
# Donal K Fellows.
#
# Version 0.31
#set -x
/sbin/mount /proc /proc -t proc
## YOU MAY NEED TO EDIT THESE FOR DIFFERENT DISTRIBUTIONS
# Location of the bootpc program
BOOTPC=/sbin/bootpc
# location of ifconfig
IFCONFIG=/sbin/ifconfig
# location of route
ROUTE=/sbin/route
# location of hostname binary
BINHOST=/bin/hostname
## Details of bootp to perform
# What device to do the bootp on
DEV=eth0
# What address to send bootp request to (broadcast by default)
#ASKSERVER="163.178.101.5"
ASKSERVER="255.255.255.255"
## Shouldn't change location, but...
# The location of the resolver config file
RCONF=/etc/resolv.conf
# location of the hosts file
EHOSTS=/etc/hosts
# For testing purposes
# BOOTPC=./bootpc
# IFCONFIG=/bin/echo
# ROUTE=/bin/echo
# BINHOST=/bin/echo
# RCONF=/tmp/resolv.conf
# EHOSTS=/tmp/hosts
# ASKSERVER="131.111.16.31"
# set -x
## Start of the functions
# Stick the nameserver lines in the resolver file.
setservers() {
# Insert the DNS servers themselves
for i in $1
do
echo "nameserver $i" >> ${RCONF}
done
}
# A function for setting the DNS stuff if we have all the info
setresolv() {
[ -f ${RCONF} ] && mv -f ${RCONF} ${RCONF}.old
# Insert provided domain
echo "domain $1" > ${RCONF}
setservers "$2"
}
# A function for setting the DNS stuff if we don't know out domainname
fakeresolv() {
[ -f ${RCONF} ] && mv -f ${RCONF} ${RCONF}.fake
# This means nothing, but provides a domain line (some(old) revolvers
# break if there isn't one present.)
echo "domain ." > ${RCONF}
setservers "$1"
}
# And putting the original back if it exists
unfakeresolv() {
[ -f ${RCONF}.fake ] && mv -f ${RCONF}.fake ${RCONF}
}
# update the DNSSERVERS but not the domainname, in case of
# reverse lookup failure.
updateresolv() {
[ -f ${RCONF} ] && mv -f ${RCONF} ${RCONF}.old
# Copy over the domainname from the old file
grep 'domain' ${RCONF}.old > ${RCONF}
setservers "$1"
}
## End of the functions
## Start of the actual work
# Mount /proc filesystem
# Bring up minimal networking
echo "Minimal networking...."
${IFCONFIG} ${DEV} up
${ROUTE} add default dev ${DEV}
# Perform the bootp -- doesn't return unless it gets an answer
echo "Calling bootp...."
#sh eval `${BOOTPC} --dev ${DEV} --server ${ASKSERVER}`
eval `${BOOTPC}`
# Take down networking
echo "Undefining network..."
${ROUTE} del default
${IFCONFIG} ${DEV} down
# Only SERVER and IPADDR are guarenteed by the bootp (assuming
# It works), so check the rest.
# Start the loopback interface etc
echo "Loopback definition...."
${IFCONFIG} lo 127.0.0.1
${ROUTE} add -net 127.0.0.0
# Setup of IP stuff needs doing first
#
echo "Displaying how interface will be configured...."
echo "---------------------------------"
echo "HOSTNAME=${HOSTNAME}"
echo "IPADDR=${IPADDR}"
echo "NETWORK=${NETWORK}"
echo "BROADCAST=${BROADCAST}"
echo "NETMASK=${NETMASK}"
echo "GATEWAYS=${GATEWAYS}"
echo "DNS servers=${DNSSRVS}"
echo "Host domain=${HOSTDOMAIN}"
echo "---------------------------------"
echo "Defining interface...."
if [ -z "${NETMASK}" ] ; then
# No netmask info, all this is guessed from the IP number
# If this is wrong for your network FIX the bootpd to know
# what it should send in the RFC1497 cookie! 11/02/94 JSP
#
${IFCONFIG} ${DEV} up ${IPADDR} broadcast ${BROADCAST}
${ROUTE} -n add -net ${NETWORK} dev ${DEV}
else
# We will have NETMASK, BROADCAST, and NETWORK defined
${IFCONFIG} ${DEV} up ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}
${ROUTE} -n add -net ${NETWORK} dev ${DEV}
fi
# Gateways need IP to be able to add the (primary) route.
#
echo "Defining gateways...."
if [ -z "${GATEWAYS}" ] ; then
# No gateways defined
echo "No IP gateways defined in rc.bootp setup"
else
# First one listed is supposedly our best, so only use it.
set - ${GATEWAYS}
${ROUTE} add default gw ${1}
fi
# May need Gateways if the DNS servers are on the other side of the
# gateways, this needs IP to be up.
#
# Can we set up DNS?
echo "Defining DNS....."
if [ ! -z "${DNSSRVS}" ]; then
if [ ! -z "${DOMAIN}" ]; then
setresolv "${DOMAIN}" "${DNSSRVS}"
else
# At least we have DNS, so use reverse lookup to get DOMAIN
# Fake the resolver setup to do the reverse lookup.
fakeresolv "${DNSSRVS}"
eval `${BOOTPC} --in2host ${IPADDR}`
unfakeresolv
if [ ! -z "${HOSTDOMAIN}" ]; then
# Got a domain, so use it
setresolv "${HOSTDOMAIN}" "${DNSSRVS}"
else
# We have DNSSRVS but no DOMAIN, and reverse lookup failed
# If the resolver file is there use it's domainname
if [ -f ${RCONF} ] ; then
echo "Using old value from /etc/resolve.conf for DOMAIN"
updateresolv "${DNSSRVS}"
else
echo "No BOOTP DOMAIN supplied"
echo " reverse lookup failed"
echo " and no existing resolver file"
echo "=> resolver setup failed"
fi
fi
fi
else
echo "No DNSSRVS supplied, resolver setup not possible"
fi
# May need DNS lookups if not provided by bootpd
#
# Set the hostname from what we got via bootp or reverse lookup
if [ ! -z "${HOSTNAME}" ]; then
${BINHOST} "${HOSTNAME}"
cat ${HOSTNAME} >> /etc/HOSTNAME
echo "127.0.0.1 loopback ${HOSTNAME} localhost">${EHOSTS}
else
if [ -z "${DONEIN2HOST}" ] ; then
eval `${BOOTPC} --in2host ${IPADDR}`
fi
if [ ! -z "${HOSTLEAF}" ]; then
${BINHOST} "${HOSTLEAF}"
echo "127.0.0.1 loopback ${HOSTLEAF} ${HOSTFULL} localhost">${EHOSTS}
fi
fi
# None of this is relevant to IP startup but may be handy for some people
#
# Tell them about other info we got back, but don't use it
# 'cos I'm too lazy to write code for this...
#
# Print out a value if present JSP
printifhere() {
[ ! -z "$2" ] && echo "$1 = $2"
}
printifhere TIMESRVS "${TIMESRVS}"
printifhere IEN116SRVS "${IEN116SRVS}"
printifhere LOGSRVS "${LOGSRVS}"
printifhere QODSRVS "${QODSRVS}"
printifhere LPRSRVS "${LPRSRVS}"
printifhere IMPRESSSRVS "${IMPRESSSRVS}"
printifhere RLPSRVS "${RLPSRVS}"
printifhere SWAPSRVR "${SWAPSRVR}"
#
#
## End of the mail work